package com.hellogood.yaohuo.server.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.hellogood.yaohuo.server.db.ConnectionPool;
import com.hellogood.yaohuo.server.db.DBHelper;
import com.hellogood.yaohuo.shared.entity.Dept;

public class DeptDAO extends DBHelper {
	Logger log = Logger.getLogger(this.getClass());
	@Override
	public List<?> initializeObject(ResultSet rs) throws SQLException {
		List<Dept> list = new ArrayList<Dept>();
		if (rs != null) {
			while (rs.next()) {
				Dept d = new Dept();
				String depCode = rs.getString("DepCode");
				if (depCode != null) {
					depCode = depCode.trim();
				}
				d.setDepCode(depCode);

				String depName = rs.getString("DepName");
				if (depName != null) {
					depName = depName.trim();
				}
				d.setDepName(depName);
				list.add(d);
			}
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<Dept> getAllDept() {
		String hxDbName = ConnectionPool.hxDbName;
		String sql = "SELECT DepCode,DepName FROM " + hxDbName + "..DEPT";
		List<?> list = super.query(sql);
		return (List<Dept>) list;
	}	

}
